//
//  XGStatusOrginalView.swift
//  WeIBo
//
//  Created by 苏文潇 on 2017/3/12.
//  Copyright © 2017年 苏文潇. All rights reserved.
//

import UIKit

//原创微博视图
class XGStatusOrginalView: UIView {

    
    var statusViewModel: XGStatusViewModel? {
        
        didSet{
            if let imageUrl = statusViewModel?.status?.user?.profile_image_url {
                userImageView.sd_setImage(with: URL(string: imageUrl), placeholderImage: UIImage(named: ""))
            }
        }
    }
    
    
//    MARK: 懒加载
    
    //  用户头像
    private lazy var userImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    
    //  认证类型等级图片
    private lazy var verifiedTypeImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
    //  昵称
    private lazy var screenNameLabel: UILabel = {
        let label = UILabel(fontSize: 14, textColor: UIColor.darkGray)
        label.text = "物理大法"
        return label
    }()
    //  会员等级图片
    private lazy var mbrankImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    //  时间
    private lazy var timeLabel: UILabel =  {
        let label = UILabel(fontSize: 12, textColor: UIColor.orange)
        
        label.text = "刚刚"
        return label
    }()
    
    //  来源
    private lazy var sourceLabel: UILabel =  {
        let label = UILabel(fontSize: 12, textColor: UIColor.lightGray)
        label.text = "来自: 星星的你"
        return label
    }()
    
    //  微博内容
    private lazy var contentLabel: UILabel =  {
        let label = UILabel(fontSize: 14, textColor: UIColor.darkGray)
        label.text = "来自: 星星的你来自: 星星的你来自: 星星的你来自: 星星的你来自: 星星的你来自: 星星的你"
        label.backgroundColor = UIColor.red
        //  多行显示
        label.numberOfLines = 0
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    private func setUI()
    {
//       self.backgroundColor = creatRandomColor() 
        
        addSubview(userImageView)
        addSubview(verifiedTypeImageView)
        addSubview(screenNameLabel)
        addSubview(mbrankImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        
        
        userImageView.snp_makeConstraints { (make) in
            make.top.equalTo(10)
            make.leading.equalTo(self).offset(10)
            make.size.equalTo(CGSize(width: 40, height: 40))
        }
        
        verifiedTypeImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(userImageView.snp_trailing)
            make.centerY.equalTo(userImageView.snp_bottom)
        }
        
        screenNameLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(userImageView.snp_trailing).offset(StatusItemMargin)
            make.top.equalTo(userImageView)
        }
        
        mbrankImageView.snp_makeConstraints { (make) in
            make.leading.equalTo(screenNameLabel.snp_trailing).offset(StatusItemMargin)
            make.top.equalTo(screenNameLabel)
        }
        
        timeLabel.snp_makeConstraints { (make) in
            make.bottom.equalTo(userImageView)
            make.leading.equalTo(screenNameLabel)
        }
        
        sourceLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(timeLabel.snp_trailing).offset(StatusItemMargin)
            make.bottom.equalTo(timeLabel)
        }
        
        contentLabel.snp_makeConstraints { (make) in
            make.top.equalTo(userImageView.snp_bottom).offset(StatusItemMargin)
            make.leading.equalTo(userImageView)
            
            make.width.equalTo(ScreenWidth - 2 * StatusItemMargin)
        }
    }
    
    
}
